import BuffUtil from '@/BuffUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 防御姿态
 **/
export default class ZS_DefensPos extends AbilityBase {
    static instance: ZS_DefensPos;
    buffType: AppBuffType = {
        id: 'buff_ZS_DefensPos',
        art: this.art,
        name: this.abilityName,
        ubertip: '受到的伤害减少，增加仇恨获得，但是造成的伤害减少',
        attribute: {
            物理伤害倍率: -0.2,
            法术伤害倍率: -0.2,
        },
    };
    constructor(id: string = 'Afyt') {
        super(id);
        ZS_DefensPos.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // BuffUtil.clearUnitBuff(source, 'buff_zs_kuangbaozitai');
        // BuffUtil.clearUnitBuff(source, 'buff_zs_zhandouzitai');
        if (BuffUtil.hasUnitBuff(source, this.buffType.id, source)) {
            BuffUtil.clearUnitBuff(source, this.buffType.id, source);
        } else {
            // let buff = BuffUtil.addBuff(source, this.buffType.id, source);
            let lv = this.getAbilityLevel(source);
            // buff.attribute.物理伤害减免 = 0.03 + 0.02 * lv;
            // buff.attribute.hatredyIncrease = 0.6 + 0.4 * lv;
            BuffCommon.addBuff({
                target: source,
                caster: source,
                ablityId: this.id,
                buffTypeId: this.buffType.id,
                attribute: {
                    物理伤害减免: 0.03 + 0.02 * lv,
                    hatredyIncrease: 0.6 + 0.4 * lv,
                },
            });
        }
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
